export class MNode {
  prev = null;
  nodeType = "";
  text = "";
  parent = null;
  lastChild = null;
  firstChild = null;
  next = null;
  unlink() {
    // 解除前地址
    if (this.prev) {
      this.prev.next = this.next;
    } else if (this.parent) {
      this.parent.firstChild = this.next;
    }
    // 解除后地址
    if (this.next) {
      this.next.prev = this.prev;
    } else if (this.parent) {
      this.parent.lastChild = this.prev;
    }
    this.parent = null;
    this.prev = null;
    this.next = null;
  }
  appendChild(mnode) {
    mnode.unlink();
    mnode.parent = this;
    // 如果有lastchild则
    if (this.lastChild) {
      this.lastChild.next = mnode;
      mnode.prev = this.lastChild;
      this.lastChild = mnode;
    } else {
      this.lastChild = this.firstChild = mnode;
    }
  }

  insertAfter(mnode) {
    console.log("??", mnode);
    mnode.unlink();
    mnode.next = this.next;

    if (mnode.next) {
      mnode.next.prev = mnode;
    }
    mnode.prev = this;
    this.next = mnode;
    mnode.parent = this.parent;
    if (!mnode.next && mnode.parent) {
      mnode.parent.lastChild = mnode;
    }
  }
}
export default MNode;
